diff --git a/Cargo.lock b/Cargo.lock index 9b22742e4e..77f0dbbc3a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -131,6 +131,12 @@ dependencies = [ "subtle", ] +[[package]] +name = "endian-num" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ad847bb2094f110bbdd6fa564894ca4556fd978958e93985420d680d3cb6d14" + [[package]] name = "env_logger" version = "0.9.3" @@ -294,12 +300,6 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "436d45c2b6a5b159d43da708e62b25be3a4a3d5550d654b72216ade4c4bfd717" -[[package]] -name = "redox_simple_endian" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "175b27da3d5db1502bd20ae0917ba132d256a2b169f1686681304ebb86504eab" - [[package]] name = "redox_syscall" version = "0.4.1" @@ -331,6 +331,7 @@ dependencies = [ "aes", "argon2", "base64ct", + "endian-num", "env_logger", "fuser", "getrandom", @@ -339,7 +340,6 @@ dependencies = [ "log", "range-tree", "redox-path", - "redox_simple_endian", "redox_syscall 0.5.1", "seahash", "termion", diff --git a/Cargo.toml b/Cargo.toml index ca50ce32ff..0bf80fc15a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,6 +35,7 @@ aes = { version = "=0.7.5", default-features = false } argon2 = { version = "0.3.4", default-features = false, features = ["alloc"] } base64ct = { version = "1", default-features = false } env_logger = { version = "0.9", optional = true } +endian-num = "0.1" getrandom = { version = "0.2.5", optional = true } libc = "0.2" log = { version = "0.4.14", default-features = false, optional = true} @@ -46,15 +47,6 @@ uuid = { version = "1.4", default-features = false } redox-path = "0.3.0" libredox = { version = "0.1.3", optional = true } -# https://github.com/rexlunae/simple-endian-rs/pull/5 -[dependencies.redox_simple_endian] -version = "0.3.0" -default-features = false -features = [ - "bitwise", "comparisons", "format", "math_ops", "neg_ops", "shift_ops", - "both_endian", "float_impls", "integer_impls", "byte_impls" -] - [features] default = ["std", "log"] force-soft = [ diff --git a/src/allocator.rs b/src/allocator.rs index 4e450ad5e4..89fc163281 100644 --- a/src/allocator.rs +++ b/src/allocator.rs @@ -1,6 +1,6 @@ use alloc::vec::Vec; use core::{fmt, mem, ops, slice}; -use simple_endian::*; +use endian_num::Le; use crate::{BlockAddr, BlockLevel, BlockPtr, BlockTrait, BLOCK_SIZE}; @@ -125,8 +125,8 @@ impl Allocator { #[repr(packed)] pub struct AllocEntry { - index: u64le, - count: i64le, + index: Le, + count: Le, } impl AllocEntry { @@ -146,11 +146,11 @@ impl AllocEntry { } pub fn index(&self) -> u64 { - { self.index }.to_native() + self.index.to_ne() } pub fn count(&self) -> i64 { - { self.count }.to_native() + self.count.to_ne() } pub fn is_null(&self) -> bool { diff --git a/src/block.rs b/src/block.rs index 59ec9fdf55..d4f75ee725 100644 --- a/src/block.rs +++ b/src/block.rs @@ -1,5 +1,5 @@ use core::{fmt, marker::PhantomData, mem, ops, slice}; -use simple_endian::*; +use endian_num::Le; use crate::BLOCK_SIZE; @@ -178,8 +178,8 @@ impl ops::DerefMut for BlockList { #[repr(packed)] pub struct BlockPtr { - addr: u64le, - hash: u64le, + addr: Le, + hash: Le, phantom: PhantomData, } @@ -193,11 +193,11 @@ impl BlockPtr { } pub fn addr(&self) -> BlockAddr { - BlockAddr({ self.addr }.to_native()) + BlockAddr(self.addr.to_ne()) } pub fn hash(&self) -> u64 { - { self.hash }.to_native() + self.hash.to_ne() } pub fn is_null(&self) -> bool { diff --git a/src/header.rs b/src/header.rs index 652c686ca4..bb58ed55a3 100644 --- a/src/header.rs +++ b/src/header.rs @@ -1,6 +1,6 @@ use core::ops::{Deref, DerefMut}; use core::{fmt, mem, slice}; -use simple_endian::*; +use endian_num::Le; use aes::{Aes128, BlockDecrypt, BlockEncrypt}; use uuid::Uuid; @@ -16,13 +16,13 @@ pub struct Header { /// Signature, should be SIGNATURE pub signature: [u8; 8], /// Version, should be VERSION - pub version: u64le, + pub version: Le, /// Disk ID, a 128-bit unique identifier pub uuid: [u8; 16], /// Disk size, in number of BLOCK_SIZE sectors - pub size: u64le, + pub size: Le, /// Generation of header - pub generation: u64le, + pub generation: Le, /// Block of first tree node pub tree: BlockPtr, /// Block of last alloc node @@ -34,7 +34,7 @@ pub struct Header { /// encrypted hash of header data without hash, set to hash and padded if disk is not encrypted pub encrypted_hash: [u8; 16], /// hash of header data without hash - pub hash: u64le, + pub hash: Le, } impl Header { @@ -58,12 +58,12 @@ impl Header { return false; } - if { self.version }.to_native() != VERSION { + if self.version.to_ne() != VERSION { // Version does not match return false; } - if { self.hash }.to_native() != self.create_hash() { + if self.hash.to_ne() != self.create_hash() { // Hash does not match return false; } @@ -77,11 +77,11 @@ impl Header { } pub fn size(&self) -> u64 { - { self.size }.to_native() + self.size.to_ne() } pub fn generation(&self) -> u64 { - { self.generation }.to_native() + self.generation.to_ne() } fn create_hash(&self) -> u64 { @@ -94,7 +94,7 @@ impl Header { fn create_encrypted_hash(&self, aes_opt: Option<&Aes128>) -> [u8; 16] { let mut encrypted_hash = [0; 16]; - for (i, b) in { self.hash }.to_native().to_le_bytes().iter().enumerate() { + for (i, b) in self.hash.to_le_bytes().iter().enumerate() { encrypted_hash[i] = *b; } if let Some(aes) = aes_opt { @@ -212,7 +212,7 @@ fn header_hash_test() { let mut header = Header::default(); assert_eq!(header.create_hash(), 0xe81ffcb86026ff96); header.update_hash(None); - assert_eq!({ header.hash }.to_native(), 0xe81ffcb86026ff96); + assert_eq!(header.hash.to_ne(), 0xe81ffcb86026ff96); assert_eq!( header.encrypted_hash, [0x96, 0xff, 0x26, 0x60, 0xb8, 0xfc, 0x1f, 0xe8, 0, 0, 0, 0, 0, 0, 0, 0] diff --git a/src/node.rs b/src/node.rs index 1b37eacf0b..136072d7d7 100644 --- a/src/node.rs +++ b/src/node.rs @@ -1,5 +1,5 @@ use core::{fmt, mem, ops, slice}; -use simple_endian::*; +use endian_num::Le; use crate::{BlockLevel, BlockList, BlockPtr, BlockTrait, RecordRaw, BLOCK_SIZE, RECORD_LEVEL}; @@ -82,18 +82,18 @@ type BlockListL4 = BlockList; /// A file/folder node #[repr(packed)] pub struct Node { - pub mode: u16le, - pub uid: u32le, - pub gid: u32le, - pub links: u32le, - pub size: u64le, - pub ctime: u64le, - pub ctime_nsec: u32le, - pub mtime: u64le, - pub mtime_nsec: u32le, - pub atime: u64le, - pub atime_nsec: u32le, - pub record_level: u32le, + pub mode: Le, + pub uid: Le, + pub gid: Le, + pub links: Le, + pub size: Le, + pub ctime: Le, + pub ctime_nsec: Le, + pub mtime: Le, + pub mtime_nsec: Le, + pub atime: Le, + pub atime_nsec: Le, + pub record_level: Le, pub padding: [u8; BLOCK_SIZE as usize - 4094], // 128 * RECORD_SIZE (16 MiB, 128 KiB each) pub level0: [BlockPtr; 128], @@ -178,39 +178,39 @@ impl Node { } pub fn mode(&self) -> u16 { - { self.mode }.to_native() + self.mode.to_ne() } pub fn uid(&self) -> u32 { - { self.uid }.to_native() + self.uid.to_ne() } pub fn gid(&self) -> u32 { - { self.gid }.to_native() + self.gid.to_ne() } pub fn links(&self) -> u32 { - { self.links }.to_native() + self.links.to_ne() } pub fn size(&self) -> u64 { - { self.size }.to_native() + self.size.to_ne() } pub fn ctime(&self) -> (u64, u32) { - ({ self.ctime }.to_native(), { self.ctime_nsec }.to_native()) + (self.ctime.to_ne(), self.ctime_nsec.to_ne()) } pub fn mtime(&self) -> (u64, u32) { - ({ self.mtime }.to_native(), { self.mtime_nsec }.to_native()) + (self.mtime.to_ne(), self.mtime_nsec.to_ne()) } pub fn atime(&self) -> (u64, u32) { - ({ self.atime }.to_native(), { self.atime_nsec }.to_native()) + (self.atime.to_ne(), self.atime_nsec.to_ne()) } pub fn record_level(&self) -> BlockLevel { - BlockLevel({ self.record_level }.to_native() as usize) + BlockLevel(self.record_level.to_ne() as usize) } pub fn set_mode(&mut self, mode: u16) { diff --git a/src/tree.rs b/src/tree.rs index d45b00fa4e..48b011c085 100644 --- a/src/tree.rs +++ b/src/tree.rs @@ -1,5 +1,5 @@ use core::{marker::PhantomData, mem, ops, slice}; -use simple_endian::*; +use endian_num::Le; use crate::{BlockLevel, BlockPtr, BlockRaw, BlockTrait}; @@ -87,7 +87,7 @@ impl ops::DerefMut for TreeList { #[repr(packed)] pub struct TreePtr { - id: u32le, + id: Le, phantom: PhantomData, } @@ -116,7 +116,7 @@ impl TreePtr { } pub fn id(&self) -> u32 { - { self.id }.to_native() + self.id.to_ne() } pub fn is_null(&self) -> bool {