diff --git a/CHANGELOG.md b/CHANGELOG.md index e046f5fb8..a17370346 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## Changed - Enforced const evaluation for `path!`. +- Removed `cstr_core` and `cty` dependencies. +- Updated `littlefs2-sys` dependency to 0.2.0. [#47]: https://github.com/trussed-dev/littlefs2/pull/47 [#57]: https://github.com/trussed-dev/littlefs2/pull/57 diff --git a/Cargo.toml b/Cargo.toml index 1cc635dfb..1b071e331 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,17 +12,10 @@ documentation = "https://docs.rs/littlefs2" [dependencies] bitflags = "1" -cty = "0.2.1" delog = "0.1.0" generic-array = "0.14" heapless = "0.7" - -[dependencies.cstr_core] -default-features = false -version = "0.2" - -[dependencies.littlefs2-sys] -version = "0.1.6" +littlefs2-sys = "0.2" [dependencies.serde] version = "1" @@ -57,3 +50,6 @@ log-error = [] # member `char name[LFS_NAME_MAX+1]`. # This means that if we change `traits::Storage::FILENAME_MAX_PLUS_ONE`, # we need to pass this on! + +[patch.crates-io] +littlefs2-sys = { git = "https://github.com/trussed-dev/littlefs2-sys.git", tag = "0.2.0" } diff --git a/src/c_stubs.rs b/src/c_stubs.rs index 92d1dc6d4..04e29f38c 100644 --- a/src/c_stubs.rs +++ b/src/c_stubs.rs @@ -2,11 +2,15 @@ //! //! Use this instead of linking to libc if you only need a handful of free functions -use cty::{c_char, c_void, size_t}; +use core::ffi::{c_char, c_void}; + +// see core::ffi::c_size_t: currently, size_t is always usize +#[allow(non_camel_case_types)] +type c_size_t = usize; extern "C" { // provided by `compiler-builtins` - fn memcpy(dst: *mut c_void, src: *const c_void, n: size_t) -> *mut c_void; + fn memcpy(dst: *mut c_void, src: *const c_void, n: c_size_t) -> *mut c_void; } /// # Safety @@ -19,7 +23,7 @@ unsafe fn strcpy(dst: *mut c_char, src: *const c_char) -> *mut c_char { /// # Safety /// `s` must point to valid memory; `s` will be treated as a null terminated string -pub unsafe fn strlen(mut s: *const c_char) -> size_t { +pub unsafe fn strlen(mut s: *const c_char) -> c_size_t { let mut n = 0; while *s != 0 { s = s.add(1); diff --git a/src/fs.rs b/src/fs.rs index a83054045..8fa16d8d1 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -1,6 +1,7 @@ //! Experimental Filesystem version using closures. use bitflags::bitflags; +use core::ffi::{c_int, c_void}; use core::ptr::addr_of; use core::ptr::addr_of_mut; use core::{ @@ -457,7 +458,7 @@ impl Filesystem<'_, Storage> { &mut self.alloc.borrow_mut().state, path.as_ptr(), id, - &mut attribute.data as *mut _ as *mut cty::c_void, + &mut attribute.data as *mut _ as *mut c_void, attr_max, ) }; @@ -489,7 +490,7 @@ impl Filesystem<'_, Storage> { &mut self.alloc.borrow_mut().state, path.as_ptr(), attribute.id, - &attribute.data as *const _ as *const cty::c_void, + &attribute.data as *const _ as *const c_void, attribute.size as u32, ) }; @@ -503,9 +504,9 @@ impl Filesystem<'_, Storage> { c: *const ll::lfs_config, block: ll::lfs_block_t, off: ll::lfs_off_t, - buffer: *mut cty::c_void, + buffer: *mut c_void, size: ll::lfs_size_t, - ) -> cty::c_int { + ) -> c_int { // println!("in lfs_config_read for {} bytes", size); let storage = unsafe { &mut *((*c).context as *mut Storage) }; debug_assert!(!c.is_null()); @@ -522,9 +523,9 @@ impl Filesystem<'_, Storage> { c: *const ll::lfs_config, block: ll::lfs_block_t, off: ll::lfs_off_t, - buffer: *const cty::c_void, + buffer: *const c_void, size: ll::lfs_size_t, - ) -> cty::c_int { + ) -> c_int { // println!("in lfs_config_prog"); let storage = unsafe { &mut *((*c).context as *mut Storage) }; debug_assert!(!c.is_null()); @@ -538,7 +539,7 @@ impl Filesystem<'_, Storage> { /// C callback interface used by LittleFS to erase data with the lower level system below the /// filesystem. - extern "C" fn lfs_config_erase(c: *const ll::lfs_config, block: ll::lfs_block_t) -> cty::c_int { + extern "C" fn lfs_config_erase(c: *const ll::lfs_config, block: ll::lfs_block_t) -> c_int { // println!("in lfs_config_erase"); let storage = unsafe { &mut *((*c).context as *mut Storage) }; let off = block as usize * Storage::BLOCK_SIZE; @@ -950,7 +951,7 @@ impl io::Read for File<'_, '_, S> { ll::lfs_file_read( &mut self.fs.alloc.borrow_mut().state, addr_of_mut!((*(*self.alloc.borrow_mut())).state), - buf.as_mut_ptr() as *mut cty::c_void, + buf.as_mut_ptr() as *mut c_void, buf.len() as u32, ) }; @@ -984,7 +985,7 @@ impl io::Write for File<'_, '_, S> { ll::lfs_file_write( &mut self.fs.alloc.borrow_mut().state, addr_of_mut!((*(*self.alloc.borrow_mut())).state), - buf.as_ptr() as *const cty::c_void, + buf.as_ptr() as *const c_void, buf.len() as u32, ) }; @@ -1214,11 +1215,11 @@ impl<'a, Storage: driver::Storage> Filesystem<'a, Storage> { // Not public, user should use `mount`, possibly after `format` fn new(alloc: &'a mut Allocation, storage: &'a mut Storage) -> Self { - alloc.config.context = storage as *mut _ as *mut cty::c_void; + alloc.config.context = storage as *mut _ as *mut c_void; - alloc.config.read_buffer = alloc.cache.read.get() as *mut cty::c_void; - alloc.config.prog_buffer = alloc.cache.write.get() as *mut cty::c_void; - alloc.config.lookahead_buffer = alloc.cache.lookahead.get() as *mut cty::c_void; + alloc.config.read_buffer = alloc.cache.read.get() as *mut c_void; + alloc.config.prog_buffer = alloc.cache.write.get() as *mut c_void; + alloc.config.lookahead_buffer = alloc.cache.lookahead.get() as *mut c_void; Filesystem { alloc: RefCell::new(alloc), diff --git a/src/path.rs b/src/path.rs index 20fe3379a..3cfc982ef 100644 --- a/src/path.rs +++ b/src/path.rs @@ -1,9 +1,13 @@ //! Paths -use core::{cmp::Ordering, convert::TryFrom, fmt, iter::FusedIterator, ops, ptr, slice, str}; - -use cstr_core::CStr; -use cty::{c_char, size_t}; +use core::{ + cmp::Ordering, + convert::TryFrom, + ffi::{c_char, CStr}, + fmt, + iter::FusedIterator, + ops, ptr, slice, str, +}; use crate::consts; @@ -404,7 +408,7 @@ pub struct PathBuf { /// # Safety /// `s` must point to valid memory; `s` will be treated as a null terminated string -unsafe fn strlen(mut s: *const c_char) -> size_t { +unsafe fn strlen(mut s: *const c_char) -> usize { let mut n = 0; while *s != 0 { s = s.add(1);